<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import{mRequest} from '@/utils/request'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        ingredientInfoId: {
          label: '辅料',
          type: 'list',
          placeholder: '请选择辅料',
          list: [],
          selectCallback: () => {
            mRequest('ingredientApi/ingredientInfoInfo', {id: this.dataForm.ingredientInfoId}, ({data}) => {
              this.dataFormConfig['tunnage']['max'] = this.R.pathOr(0, ['ingredientInfo', 'residueWeightCount'], data)
            })
          }
        },
        tunnage: {
          label: '吨数',
          type: 'number',
          max: 1000,
          reply: 'ingredientInfoId'
        },
        dayTime: {
          label: '日期',
          type: 'date',
          placeholder: '请选择日期'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.initIngredientInfoList()

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('ingredientInfoId', 'tunnage', 'dayTime', 'status'),
        initApi: 'ingredientApi/ingredientLeaveInfo',
        saveApi: 'ingredientApi/saveIngredientLeave',
        updateApi: 'ingredientApi/updateIngredientLeave',
        objectName: 'ingredientLeave'
      })
    }
  }
}
</script>
